<?php
include("../includes/common.php");
if($conf['forcelogin']==1 && !$islogin2) {loginsmsg('请登录后再操作！');}
$title='我的文件';
include './head.php';
$csrf_token = md5(mt_rand(0,999).time());
$_SESSION['csrf_token'] = $csrf_token;
?>

<div class="layui-fluid">
    <div class="layui-card">
        <div id="divLoading">
          <div class="layui-card-header"><?=$title;?></div>
            <div class="layui-card-body layui-form">
                <input type="hidden" id="csrf_token" name="csrf_token" value="<?php echo $csrf_token?>">
            	<!-- 表格工具栏 -->
            	<form class="layui-form toolbar">
            		<div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">选择类型</label>
                            <div class="layui-input-block">
                                <select name="type">
                                    <option value="0">全部</option>
                                    <option value="1">ID</option>
                                    <option value="2">名称</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
            				<label class="layui-form-label w-auto">搜索数据：</label>
            				<div class="layui-input-inline mr0">
            					<input type="text" name="kw" class="layui-input" placeholder="请输入你所要搜索的内容！" />
            				</div>
            			</div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">搜索类别</label>
                            <div class="layui-input-block">
                                <select name="method">
                                    <option value="0">精确搜索</option>
                                    <option value="1">模糊搜索</option>
                                </select>
                            </div>
                        </div>
            			<div class="layui-inline">
            				<button class="layui-btn icon-btn" lay-filter="roleTbSearch" lay-submit>
            					<i class="layui-icon">&#xe615;</i>搜索
            				</button>
            			</div>
            		</div>
            	</form>
            <!-- 数据表格 -->
            <table class="layui-hide" id="group_list" lay-filter="group_list"></table>
            <script id="table_button" type="text/html">
                <a lay-event="del" class="layui-btn layui-btn-danger layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
            </div>
        </div>
    </div>
</div>
    
  
      
<?php include 'foot.php';?>

<script type="text/javascript">
    layui.use(['jquery', 'layer', 'notice', 'form', 'table', 'admin', 'element', 'xmSelect', 'tagsInput'],function() {
        var $ = layui.jquery;
        var layer = layui.layer;
        var notice = layui.notice;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var xmSelect = layui.xmSelect;
        var tagsInput = layui.tagsInput;
       


        var insTb = table.render({
            elem: '#group_list',
            url: './ajax.php?act=home&m=mine',
            where: function(){
                var kw = $('input[name=kw]').val();
                return kw ? {kw: kw} : {};
            }(),
            text: {
                none: '暂无文件' // 默认：无数据
            },
            page: true,
            skin: 'line',
            cellMinWidth: 100,
            limit: 10,
            cols: [[
                {
                    field: 'id',
                    title: '编号',
                    templet: function(d){
                        return '<span class="layui-badge layui-badge-blue">'+ d.id +'</span>';
                    },
                    align: 'center',
                    width: 80,
                    sort: true
                },
                {
                    field: 'name',
                    title: '文件名',
                    templet: function(d){
                        return '<a href="'+ d.file_url +'" target="_blank">'+ d.name +'</a>';
                    },
                    align: 'center',
                    width: 380
                },
                {
                    field: 'hash',
                    title: 'hash',
                    templet: function(d){
                        return '<span class="layui-badge layui-badge-blue">'+ d.hash +'</span>';
                    },
                    align: 'center',
                    width: 280,
                    sort: true
                },
                {
                    field: 'type',
                    title: '类型',
                    align: 'center',
                    width: 100
                },
                {
                    field: 'size',
                    title: '大小(Byte)',
                    align: 'center',
                    width: 120
                },
                {
                    field: 'size',
                    title: '下载次数',
                    align: 'center',
                    width: 120
                },
                {
                    field: 'addtime',
                    title: '上传时间',
                    align: 'center',
                    width: 180,
                    sort: true
                },
                {
                    field: 'storage_type',
                    title: '存储',
                    align: 'center',
                    width: 120
                },
                {
                    field: "action",
                    title: "功能操作",
                    toolbar: "#table_button",
                    align: 'center',
                    width: 220
                }
            ]]
        });
        
        /* 表格搜索 */
        form.on('submit(roleTbSearch)', function(data) {
            insTb.reload({
                where: data.field,
                page: { curr: 1 }
            });
            return false;
        });

       

       

        /* 表格工具栏 */
        table.on('tool(group_list)', function(obj) {
           var csrf_token = $("#csrf_token").val();
            if (obj.event === "del") {
                layer.confirm('你确实要删除此数据吗？', {
                        btn: ['确定', '取消'],
                        closebtn: 0,
                        icon: 3
                    },
                    function(index) {
                        $.ajax({
                            type: "POST",
                            url: "ajax.php?act=deleteFile",
                            data: {
                                hash: obj.data.hash,
                                csrf_token: csrf_token
                            },
                            dataType: "json",
                            success: function(data) {
                                if (data.code == 0) {
                                    notice.success({
                                        title: '消息通知',
                                        message: data.msg,
                                        position: 'topCenter',
                                        audio: ''
                                    });
                                    insTb.reload();
                                } else {
                                    notice.error({
                                        title: '消息通知',
                                        message: data.msg,
                                        position: 'topCenter',
                                        audio: ''
                                    });
                                }
                            }
                        });
                        layer.close(index);
                    },
                function() {});
            } 
        });

    });
</script>
